package com.jobanalysis.job_analysis.controller;

import com.jobanalysis.job_analysis.dto.CityJobClassSalaryDto;
import com.jobanalysis.job_analysis.dto.ProfeJob;
import com.jobanalysis.job_analysis.dto.ProfessionDto;
import com.jobanalysis.job_analysis.entity.JobSort;
import com.jobanalysis.job_analysis.service.IJobService;
import com.jobanalysis.job_analysis.util.HDFSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/")
public class BigDataController {

    @Autowired
    private IJobService jobService;


    @Autowired
    private HDFSUtil hdfsUtil;

    @RequestMapping("/test")
    public String test(String path) throws IOException {
        hdfsUtil.ls(path);
        return "ok";

    }

    /**
     * 行业占比分析
     */
    @RequestMapping(value = "/proanaly", method = RequestMethod.GET)
    public List<ProfessionDto> professionSort() {
        return jobService.professionAnalysis();
    }

    /**
     * 职位区域分析
     */
    @RequestMapping(value = "/professionareaanalysis", method = RequestMethod.GET)
    public List<ProfeJob> proAreaAnalysis() {
        return jobService.getProfessionJobArea();
    }

    /**
     * 薪资水平分析
     *
     * @return
     */
    @RequestMapping(value = "/salaryanalysis", method = RequestMethod.POST)
    public List<CityJobClassSalaryDto> salaryAnalysis(String[] cities, String reAnalysis) {
        if (cities.length > 0) {
            cities[0] = cities[0].substring(1);
            cities[cities.length - 1] = cities[cities.length - 1].substring(0, cities[cities.length - 1].length() - 1);
            for (int i = 0; i < cities.length; i++) {
                cities[i] = cities[i].substring(1);
                cities[i] = cities[i].substring(0, cities[i].length() - 1);
            }
        }
        return jobService.analysisSalary(cities, reAnalysis);
    }

    @GetMapping("/listJobSortAll")
    public Map listJobSortAll() {
        Map map = new HashMap<>();
        List<JobSort> res = jobService.listJobSortAll();

        map.put("status", 200);
        map.put("length", res.size());
        map.put("res", res);
        return map;
    }


    /**
     * 预测准备
     */
    @GetMapping("/predictPrepared")
    public void predictPrepared() {
        jobService.predictPrepared();
    }


}
